/* Copyright (C) 2012  Chris Mueller <ruunsmail@googlemail.com>
 *
 * This file is part of the Liquid Programming Language
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef LIQUID__NODES_H_
#define LIQUID__NODES_H_

#include "base.h"
#include <gmp.h>

G_BEGIN_DECLS

struct LqPtrArray;
struct LqContext;
struct LqMap;

enum LqNodeKind {
    LQ_NODE_BAND = '&',
    LQ_NODE_MULTIPLY = '*',
    LQ_NODE_PLUS = '+',
    LQ_NODE_MINUS = '-',
    LQ_NODE_DIVIDE = '/',
    LQ_NODE_SCOPING = ':',
    LQ_NODE_POWER = '^',
    LQ_NODE_LESS = '<',
    LQ_NODE_ASSIGN = '=',
    LQ_NODE_GREATER = '>',
    LQ_NODE_BOR = '|',
    LQ_NODE_BNOT = '~',
    LQ_NODE_ROOT,
    LQ_NODE_BLOCK,
    LQ_NODE_BITSHIFTLEFT,
    LQ_NODE_BITSHIFTRIGHT,
    LQ_NODE_BXOR,
    LQ_NODE_MODULO,
    LQ_NODE_AND,
    LQ_NODE_OR,
    LQ_NODE_NOT,
    LQ_NODE_NOTEQUAL,
    LQ_NODE_EQUAL,
    LQ_NODE_LESSEQUAL,
    LQ_NODE_GREATEREQUAL,
    LQ_NODE_MINUS_SIGN,
    LQ_NODE_CONCAT,
    LQ_NODE_REDUCE,
    LQ_NODE_CONS,
    LQ_NODE_INDEX,
    LQ_NODE_INTEGER,
    LQ_NODE_CHARACTER,
    LQ_NODE_FLOATPOINT,
    LQ_NODE_STRING,
    LQ_NODE_ATOM,
    LQ_NODE_UNDERSCORE,
    LQ_NODE_TUPLE,
    LQ_NODE_LIST,
    LQ_NODE_LIST_GENERATOR,
    LQ_NODE_VALUE,
    LQ_NODE_IDENTIFIER,
    LQ_NODE_CALL,
    LQ_NODE_PATTERN,
    LQ_NODE_LET,
    LQ_NODE_IF,
    LQ_NODE_MATCH,
    LQ_NODE_BY,
    LQ_NODE_FUN,
    LQ_NODE_MODULE
};


struct LqNode {
    int line;
    enum LqNodeKind kind;

    struct LqPtrArray* children;
    struct LqMap* symbols;

    union {
        mpz_t integer;
        mpf_t floatpoint;
        byte* string;
        gunichar character;
    };
};


struct LqNode*          lq_node_new(int line, enum LqNodeKind kind, size_t children);
void                    lq_node_free(struct LqNode* node);

void                    lq_node_append(struct LqNode* parent, struct LqNode* child);
size_t                  lq_node_children(struct LqNode* node);
struct LqNode*          lq_node_index(struct LqNode* parent, size_t index);

byte*                   lq_node_to_string(const struct LqNode* node); 

struct LqNode*          lq_node_integer_new(int line, byte* text, guint base);
struct LqNode*          lq_node_floatpoint_new(int line, byte* text);
struct LqNode*          lq_node_character_new(int line, byte* text);
struct LqNode*          lq_node_string_new(int line, byte* text, gboolean raw);
struct LqNode*          lq_node_atom_new(int line, byte* text);

struct LqNode*          lq_node_identifier_new(int line, byte* text);
struct LqNode*          lq_node_value_new(int line, byte* text);

struct LqNode*          lq_node_module_new(int line, byte* text);
struct LqNode*          lq_node_let_new(int line, byte* text);

G_END_DECLS


#endif // LIQUID__NODES_H_
